/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.gradecalculator.plugin.core.srdx.internal;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlElementRefs;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(namespace = "http://gradecalculator.net/", name = "moduleList")
@XmlSeeAlso({XmlModule.class, XmlIndividualModule.class, XmlSelectableModuleLists.class})
@XmlType( 
 name = "moduleList",
 propOrder = { "name", "sortOrder", "modules" } 
) 
public class XmlModuleList implements IXmlModuleIdentificator {
	private String name;
	private List<IXmlModuleListItem> modules = new ArrayList<IXmlModuleListItem>();
	private int sortOrder;
	private IXmlModuleIdentificator parent;

	@Override
	@XmlTransient
	public IXmlModuleIdentificator getParent()
	{
		return parent;
	}
	@Override
	public void setParent(final IXmlModuleIdentificator parent)
	{
		this.parent = parent;
	}

	@XmlElementWrapper(name="modules")
	@XmlElementRefs({
		    @XmlElementRef(type=XmlModule.class),
		    @XmlElementRef(type=XmlIndividualModule.class),
		    @XmlElementRef(type=XmlSelectableModuleLists.class)
		  })
	public List<IXmlModuleListItem> getModules() {
		return modules;
	}
	public void setModules(final List<IXmlModuleListItem> modules) {
		this.modules = modules;
	}

	@XmlElement(name = "sortorder")
	public int getSortOrder() {
		return sortOrder;
	}
	public void setSortOrder(final int sortOrder) {
		this.sortOrder = sortOrder;
	}

	@XmlElement(name = "name")
	public String getName() {
		return name;
	}
	public void setName(final String name) {
		this.name = name;
	}

	@Override
	public String getIdentifier() {
		if (parent != null) {
			return parent.getIdentifier() + "." + name;
		}
		return name;
	}
}
